<template>
  <div class="block-wrapper">
    <div class="block">
      <div class="top-img-wrapper">
        <img :src="src" style="width: 100%; height: 100%;" :style="{height: imgHeight + 'px'}" alt="">
      </div>
      <div class="text-wrapper">
        <h3>{{describe}}</h3>
        <h4>{{title}}</h4>
        <p>￥{{price}}</p>
      </div>
      <div class="flag">
        <div class="flag-img">
            <img src="/static/tabs/flag1.png" style="width: 25px; height: 30px;" alt="" v-if="showOne">
            <img src="/static/tabs/flag2.png" style="width: 25px; height: 30px;" alt="" v-if="showTwo">
            <img src="/static/tabs/flag3.png" style="width: 25px; height: 30px;" alt="" v-if="showThree">
        </div>
        <div class="number" v-if="showNumber">
            <span>{{ranking}}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import imgView from './imgView'
export default {
  components: {
    imgView
  },
  data () {
    return {
      showOne: false,
      showTwo: false,
      showThree: false,
      showNumber: true
    }
  },
  props: {
    src: {
      type: String,
      default: ''
    },
    describe: {
      type: String,
      default: ''
    },
    title: {
      type: String,
      default: ''
    },
    price: {
      type: String,
      default: ''
    },
    ranking: {
      type: Number
    },
    imgHeight: {
      type: Number
    }
  },
  methods: {
    showRanking () {
      if (this.ranking) {
        switch (this.ranking) {
          case 1:
            this.showOne = true
            break
          case 2:
            this.showTwo = true
            break
          case 3:
            this.showThree = true
            break
        }
      } else {
      }
    }
  },
  mounted () {
    this.showRanking()
  }
}
</script>

<style lang="scss" scoped>
.block-wrapper {
    // height: 220px;
    background: #fff;
    box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    .block {
        position: relative;
        .top-img-wrapper {
            width: 100%;
            // height: 128px;
            overflow: hidden;
            border-radius: 10px;
        }
        .text-wrapper {
            // height: 90px;
            margin-top: 10px;
            margin-left: 5px;
            h3 {
                font-weight: 700;
                font-size: 14px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
            }
            h4 {
                font-size: 12px;
                color: #ccc;
                // margin-top: 5px;
            }
            p {
                margin-top: 5px;
                font-size: 14px;
                font-weight: 700;
            }
        }
        .flag {
            position: absolute;
            top: -10px;
            left: 10px;
            .number {
                position: absolute;
                top: -1px;
                left: 12px;
                span {
                    font-size: 12px;
                    color: #fff;
                }
            }
        }
    }
}
</style>
